package com.tanhua.admin.module.dynamicmanage.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.tanhua.admin.module.dynamicmanage.service.MessagePassAndRejectService;
import com.tanhua.common.mapper.PublishInfoMapper;
import com.tanhua.common.pojo.PublishInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
public class MessagePassAndRejectServiceImpl implements MessagePassAndRejectService {

    @Autowired
    private PublishInfoMapper publishInfoMapper;

    /**
     * 审核通过
     * @param id
     * @return
     */
    public Map<String,String> messagePass(String[] id) {

            Map<String,String> result = new HashMap<>();
            if (ObjectUtil.isNotEmpty(id)){
                UpdateWrapper<PublishInfo> updateWrapper = new UpdateWrapper<>();
                updateWrapper.eq("publish_id",id[0]).set("state",5);
                int update = publishInfoMapper.update(null, updateWrapper);
                if (update==1){
                    result.put("message","操作成功");
                    return result;
                }
            }
            result.put("message","操作失败");
            return result;
        }

            /*if (StrUtil.isEmpty(id)){
                return null;
            }

        try {
            UpdateWrapper<PublishInfo> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("publish_id",id);
            PublishInfo publishInfo = new PublishInfo();
            publishInfo.setState("5");
            this.publishInfoMapper.update(publishInfo,updateWrapper);
            return "审核通过";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null; */



    /**
     * 审核拒绝
     * @param id
     * @return
     */
    public Map<String,String> messageReject(String[] id) {

        Map<String,String> result = new HashMap<>();
        if (ObjectUtil.isNotEmpty(id)){
            UpdateWrapper<PublishInfo> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("publish_id",id[0]).set("state",4);
            int update = publishInfoMapper.update(null, updateWrapper);
            if (update==1){
                result.put("message","操作成功");
                return result;
            }
        }
        result.put("message","操作失败");
        return result;

        /*if (StrUtil.isEmpty(id)){
            return null;
        }

        try {
            UpdateWrapper<PublishInfo> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("publish_id",id);
            PublishInfo publishInfo = new PublishInfo();
            publishInfo.setState("4");
            this.publishInfoMapper.update(publishInfo,updateWrapper);
            return "审核拒绝";
        } catch (Exception e) {
            e.printStackTrace();
        }*/
    }
}
